package bb.lanxing.model.jsonlocal;

import static java.lang.Math.round;

import java.util.List;

import bb.lanxing.model.database.Segment;
import bb.lanxing.model.database.Trackpoint;
import bb.lanxing.model.database.Workout;
import bb.lanxing.model.json.ServerUser;
import bb.lanxing.model.json.TrackSegment;
import bb.lanxing.model.json.WorkoutExtraInfo;
import bb.lanxing.util.CommonUtil;

public class JWorkout {

    private int avgCadence;
    private int avgHeartrate;
    private double avgHeatKm;
    private String avgHeatKmRate;
    private double avgPower;
    private double avgSpeed;
    private int cadence;
    private int cadenceSource;
    private int calorie;
    private int category;
    private int commentCount;
    private double credits;
    private double creditsDvalue;
    private String description;
    private double distance;
    private double downDistance;
    private long downDuration;
    private long duration;
    private float elevationGain;
    private float elevationLoss;
    private String encodingPoints;
    private int endCadence;
    private long endTime;
    private int endWheel;
    private String equipmentInfo;
    private String fitPath;
    private double flatDistance;
    private long flatDuration;
    private int fullData;

    private float grade;
    private int heartSource;
    private int heartrate;
    private int hidden;

    private long clientId;
    private int isExport;
    private int isLike;
    private int isValid;
    private long lastUpload;
    private int likeCount;
    private int locSource;
    private int mapHidden;
    private int mapId;
    private String mapUrl;
    private int matchedSegments;
    private int maxCadence;
    private int maxGrade;
    private int maxHeartrate;
    private double maxPower;
    private double maxSpeed;
    private int maxWheelRevolution;
    private String mergeRecord;
    private int minGrade;
    private long modifyTime;
    private long pauseDuration;
    private String poi;
    private long pointCounts;
    private double powerFTP;
    private double powerIF;
    private double powerNP;
    private int powerSource;
    private double powerTSS;
    private double powerVI;
    private double realtimeSpeed;
    private String segmentCa;
    private String segmentHr;
    private String segmentIndex;
    private String segmentKM;
    private String segmentSport;
    private long serverId;

    private ServerUser serverUser;
    private String slopeGradeMax;
    private int sport;
    private int startCadence;
    private long startTime;
    private int startWheel;
    private int step;
    private int synchronise;
    private String threedWorkout;
    private String thumbnail;
    private String title;

    private List<Trackpoint> trackPoints;

    private List<TrackSegment> trackSegments;
    private int typeChangeCount;
    private double upDistance;
    private long upDuration;
    private int uploadStatus;
    private long uploadTime;
    private long userId;
    private String uuid;

    private double avgAltitude;

    private double maxAltitude;

    private double minAltitude;

    private int workStatus;

    public void setMaxAltitude(double maxAltitude) {
        this.maxAltitude = maxAltitude;
    }

    public double getMaxAltitude() {
        return maxAltitude;
    }

    public void setWorkStatus(int workStatus) {
        this.workStatus = workStatus;
    }

    public int getWorkStatus() {
        return workStatus;
    }



    public void setAvgAltitude(double avgAltitude) {
        this.avgAltitude = avgAltitude;
    }

    public double getAvgAltitude() {
        return avgAltitude;
    }



    public void setDistance(double distance) {
        this.distance = distance;
    }

    public double getDistance() {
        return distance;
    }

    public void setDownDistance(double downDistance) {
        this.downDistance = downDistance;
    }

    public double getDownDistance() {
        return downDistance;
    }

    public void setDownDuration(long downDuration) {
        this.downDuration = downDuration;
    }

    public long getDownDuration() {
        return downDuration;
    }

    public void setDuration(long duration) {
        this.duration = duration;
    }

    public long getDuration() {
        return duration;
    }

    public void setElevationGain(float elevationGain) {
        this.elevationGain = elevationGain;
    }

    public float getElevationGain() {
        return elevationGain;
    }

    public void setElevationLoss(float elevationLoss) {
        this.elevationLoss = elevationLoss;
    }

    public float getElevationLoss() {
        return elevationLoss;
    }

    public void setEndTime(long endTime) {
        this.endTime = endTime;
    }

    public long getEndTime() {
        return endTime;
    }

    public void setFlatDistance(double flatDistance) {
        this.flatDistance = flatDistance;
    }

    public double getFlatDistance() {
        return flatDistance;
    }

    public void setFlatDuration(long flatDuration) {
        this.flatDuration = flatDuration;
    }

    public long getFlatDuration() {
        return flatDuration;
    }

    public void setHidden(int hidden) {
        this.hidden = hidden;
    }

    public int getHidden() {
        return hidden;
    }

    public void setClientId(long clientId) {
        this.clientId = clientId;
    }

    public long getClientId() {
        return clientId;
    }

    public void setLastUpload(long lastUpload) {
        this.lastUpload = lastUpload;
    }

    public long getLastUpload() {
        return lastUpload;
    }

    public void setMaxGrade(int maxGrade) {
        this.maxGrade = maxGrade;
    }

    public int getMaxGrade() {
        return maxGrade;
    }

    public void setMinGrade(int minGrade) {
        this.minGrade = minGrade;
    }

    public int getMinGrade() {
        return minGrade;
    }

    public void setServerId(long serverId) {
        this.serverId = serverId;
    }

    public long getServerId() {
        return serverId;
    }

    public void setSport(int sport) {
        this.sport = sport;
    }

    public int getSport() {
        return sport;
    }

    public void setAvgCadence(int avgCadence) {
        this.avgCadence = avgCadence;
    }

    public int getAvgCadence() {
        return avgCadence;
    }

    public void setAvgHeartrate(int avgHeartrate) {
        this.avgHeartrate = avgHeartrate;
    }

    public int getAvgHeartrate() {
        return avgHeartrate;
    }

    public void setAvgHeatKm(double avgHeatKm) {
        this.avgHeatKm = avgHeatKm;
    }

    public double getAvgHeatKm() {
        return avgHeatKm;
    }

    public void setAvgHeatKmRate(String avgHeatKmRate) {
        this.avgHeatKmRate = avgHeatKmRate;
    }

    public String getAvgHeatKmRate() {
        return avgHeatKmRate;
    }

    public void setAvgPower(double avgPower) {
        this.avgPower = avgPower;
    }

    public double getAvgPower() {
        return avgPower;
    }

    public void setAvgSpeed(double avgSpeed) {
        this.avgSpeed = avgSpeed;
    }

    public double getAvgSpeed() {
        return avgSpeed;
    }

    public void setCadence(int cadence) {
        this.cadence = cadence;
    }

    public int getCadence() {
        return cadence;
    }

    public void setCadenceSource(int cadenceSource) {
        this.cadenceSource = cadenceSource;
    }

    public int getCadenceSource() {
        return cadenceSource;
    }

    public void setCalorie(int calorie) {
        this.calorie = calorie;
    }

    public int getCalorie() {
        return calorie;
    }

    public void setCategory(int category) {
        this.category = category;
    }

    public int getCategory() {
        return category;
    }

    public void setCommentCount(int commentCount) {
        this.commentCount = commentCount;
    }

    public int getCommentCount() {
        return commentCount;
    }

    public void setCredits(double credits) {
        this.credits = credits;
    }

    public double getCredits() {
        return credits;
    }

    public void setCreditsDvalue(double creditsDvalue) {
        this.creditsDvalue = creditsDvalue;
    }

    public double getCreditsDvalue() {
        return creditsDvalue;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getDescription() {
        return description;
    }

    public void setEncodingPoints(String encodingPoints) {
        this.encodingPoints = encodingPoints;
    }

    public String getEncodingPoints() {
        return encodingPoints;
    }

    public void setEndCadence(int endCadence) {
        this.endCadence = endCadence;
    }

    public int getEndCadence() {
        return endCadence;
    }

    public void setEndWheel(int endWheel) {
        this.endWheel = endWheel;
    }

    public int getEndWheel() {
        return endWheel;
    }

    public void setEquipmentInfo(String equipmentInfo) {
        this.equipmentInfo = equipmentInfo;
    }

    public String getEquipmentInfo() {
        return equipmentInfo;
    }

    public void setExport(int export) {
        isExport = export;
    }

    public int getExport(){
        return isExport;
    }

    public void setFitPath(String fitPath) {
        this.fitPath = fitPath;
    }

    public String getFitPath() {
        return fitPath;
    }

    public void setFullData(int fullData) {
        this.fullData = fullData;
    }

    public int getFullData(){
        return fullData;
    }

    public void setGrade(float grade) {
        this.grade = grade;
    }

    public float getGrade() {
        return grade;
    }

    public void setHeartrate(int heartrate) {
        this.heartrate = heartrate;
    }

    public int getHeartrate() {
        return heartrate;
    }

    public void setHeartSource(int heartSource) {
        this.heartSource = heartSource;
    }

    public int getHeartSource() {
        return heartSource;
    }

    public void setLike(int like) {
        isLike = like;
    }

    public int getLike(){
        return isLike;
    }

    public void setLikeCount(int likeCount) {
        this.likeCount = likeCount;
    }

    public int getLikeCount() {
        return likeCount;
    }

    public void setLocSource(int locSource) {
        this.locSource = locSource;
    }

    public int getLocSource() {
        return locSource;
    }

    public void setMapHidden(int mapHidden) {
        this.mapHidden = mapHidden;
    }

    public int getMapHidden() {
        return mapHidden;
    }

    public void setMapId(int mapId) {
        this.mapId = mapId;
    }

    public int getMapId() {
        return mapId;
    }

    public void setMapUrl(String mapUrl) {
        this.mapUrl = mapUrl;
    }

    public String getMapUrl() {
        return mapUrl;
    }

    public void setMatchedSegments(int matchedSegments) {
        this.matchedSegments = matchedSegments;
    }

    public int getMatchedSegments() {
        return matchedSegments;
    }

    public void setMaxCadence(int maxCadence) {
        this.maxCadence = maxCadence;
    }

    public int getMaxCadence() {
        return maxCadence;
    }

    public void setMaxHeartrate(int maxHeartrate) {
        this.maxHeartrate = maxHeartrate;
    }

    public int getMaxHeartrate() {
        return maxHeartrate;
    }

    public void setMaxPower(double maxPower) {
        this.maxPower = maxPower;
    }

    public double getMaxPower() {
        return maxPower;
    }

    public void setMaxSpeed(double maxSpeed) {
        this.maxSpeed = maxSpeed;
    }

    public double getMaxSpeed() {
        return maxSpeed;
    }

    public void setMaxWheelRevolution(int maxWheelRevolution) {
        this.maxWheelRevolution = maxWheelRevolution;
    }

    public int getMaxWheelRevolution() {
        return maxWheelRevolution;
    }

    public void setMergeRecord(String mergeRecord) {
        this.mergeRecord = mergeRecord;
    }

    public String getMergeRecord() {
        return mergeRecord;
    }

    public void setModifyTime(long modifyTime) {
        this.modifyTime = modifyTime;
    }

    public long getModifyTime() {
        return modifyTime;
    }

    public void setPauseDuration(long pauseDuration) {
        this.pauseDuration = pauseDuration;
    }

    public long getPauseDuration() {
        return pauseDuration;
    }

    public void setPoi(String poi) {
        this.poi = poi;
    }

    public String getPoi() {
        return poi;
    }

    public void setPointCounts(long pointCounts) {
        this.pointCounts = pointCounts;
    }

    public long getPointCounts() {
        return pointCounts;
    }

    public void setPowerFTP(double powerFTP) {
        this.powerFTP = powerFTP;
    }

    public double getPowerFTP() {
        return powerFTP;
    }

    public void setPowerIF(double powerIF) {
        this.powerIF = powerIF;
    }

    public double getPowerIF() {
        return powerIF;
    }

    public void setPowerNP(double powerNP) {
        this.powerNP = powerNP;
    }

    public double getPowerNP() {
        return powerNP;
    }

    public void setPowerSource(int powerSource) {
        this.powerSource = powerSource;
    }

    public int getPowerSource() {
        return powerSource;
    }

    public void setPowerTSS(double powerTSS) {
        this.powerTSS = powerTSS;
    }

    public double getPowerTSS() {
        return powerTSS;
    }

    public void setPowerVI(double powerVI) {
        this.powerVI = powerVI;
    }

    public double getPowerVI() {
        return powerVI;
    }

    public void setRealtimeSpeed(double realtimeSpeed) {
        this.realtimeSpeed = realtimeSpeed;
    }

    public double getRealtimeSpeed() {
        return realtimeSpeed;
    }

    public void setSegmentCa(String segmentCa) {
        this.segmentCa = segmentCa;
    }

    public String getSegmentCa() {
        return segmentCa;
    }

    public void setSegmentHr(String segmentHr) {
        this.segmentHr = segmentHr;
    }

    public String getSegmentHr() {
        return segmentHr;
    }

    public void setSegmentIndex(String segmentIndex) {
        this.segmentIndex = segmentIndex;
    }

    public String getSegmentIndex() {
        return segmentIndex;
    }

    public void setSegmentKM(String segmentKM) {
        this.segmentKM = segmentKM;
    }

    public String getSegmentKM() {
        return segmentKM;
    }

    public void setSegmentSport(String segmentSport) {
        this.segmentSport = segmentSport;
    }

    public String getSegmentSport() {
        return segmentSport;
    }

    public void setServerUser(ServerUser serverUser) {
        this.serverUser = serverUser;
    }

    public ServerUser getServerUser() {
        return serverUser;
    }

    public void setSlopeGradeMax(String slopeGradeMax) {
        this.slopeGradeMax = slopeGradeMax;
    }

    public String getSlopeGradeMax() {
        return slopeGradeMax;
    }

    public void setStartCadence(int startCadence) {
        this.startCadence = startCadence;
    }

    public int getStartCadence() {
        return startCadence;
    }

    public void setStartTime(long startTime) {
        this.startTime = startTime;
    }

    public long getStartTime() {
        return startTime;
    }

    public void setStartWheel(int startWheel) {
        this.startWheel = startWheel;
    }

    public int getStartWheel() {
        return startWheel;
    }

    public void setStep(int step) {
        this.step = step;
    }

    public int getStep() {
        return step;
    }

    public void setSynchronise(int synchronise) {
        this.synchronise = synchronise;
    }

    public int getSynchronise() {
        return synchronise;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getTitle() {
        return title;
    }

    public void setUpDistance(double upDistance) {
        this.upDistance = upDistance;
    }

    public double getUpDistance() {
        return upDistance;
    }

    public void setUpDuration(long upDuration) {
        this.upDuration = upDuration;
    }

    public long getUpDuration() {
        return upDuration;
    }

    public void setUploadStatus(int uploadStatus) {
        this.uploadStatus = uploadStatus;
    }

    public int getUploadStatus() {
        return uploadStatus;
    }

    public void setUserId(long userId) {
        this.userId = userId;
    }

    public long getUserId() {
        return userId;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public String getUuid() {
        return uuid;
    }



    public static JWorkout create(Workout workout) {
        JWorkout jWorkout = new JWorkout();
        WorkoutExtraInfo workoutExtraInfo = Workout.getWorkoutExtraInfo(workout.getId());

        String strEmpty = "";

        jWorkout.setDistance(workout.getDistance());//MonitoringReader.DISTANCE_STRING
        jWorkout.setDownDistance(workout.getDownDistance());
        jWorkout.setDownDuration(workout.getDownDuration());
        jWorkout.setDuration(workout.getDuration());
        jWorkout.setElevationGain(workout.getElevationGain());
        jWorkout.setElevationLoss(workout.getElevationLoss());
        jWorkout.setEndTime(workout.getEndTime());
        jWorkout.setFlatDistance(workout.getFlatDistance());
        jWorkout.setFlatDuration(workout.getFlatDuration());
        jWorkout.setHidden(workout.getHidden());
        jWorkout.setClientId(workout.getId());
        jWorkout.setLastUpload(workout.getLastUpload());
        jWorkout.setMaxGrade(workout.getMaxGrade());
        jWorkout.setMinGrade(workout.getMinGrade());
        jWorkout.setServerId(workout.getServerId());
        jWorkout.setSport(workout.getSport());//SettingSupports.SUPPORT_ITEM_SPORT
        jWorkout.setStartTime(workout.getStartTime());
        jWorkout.setTitle( workout.getTitle() == null ? strEmpty : workout.getTitle());
        jWorkout.setDescription(workout.getDescription() == null ? strEmpty : workout.getDescription());
        jWorkout.setUpDistance(workout.getUpDistance());
        jWorkout.setUpDuration(workout.getUpDuration());
        jWorkout.setUploadStatus(workout.getUploadStatus().ordinal());
        jWorkout.setWorkStatus(workout.getWorkStatus());
        jWorkout.setUserId(workout.getUserId());
        jWorkout.setUuid(workout.getUuid() == null ? strEmpty : workout.getUuid());
        jWorkout.setMaxCadence(workout.getMaxCadence());
        jWorkout.setAvgCadence(workout.getAvgCadence());
        jWorkout.setStartCadence(workout.getStartCadence());
        jWorkout.setEndCadence(workout.getEndCadence());
        String equipmentInfo = workout.getEquipmentInfo() == null ? strEmpty : workout.getEquipmentInfo();
        jWorkout.setEquipmentInfo(equipmentInfo);
        String fitPath = workout.getFitPath() == null ? strEmpty : workout.getFitPath();
        jWorkout.setFitPath(fitPath);
//        jWorkout.setCadence(workout.getCadence());
//        jWorkout.setPointCounts(workout.getPointCounts());
//        jWorkout.setHeartrate(workout.getHeartrate());
        jWorkout.setMaxHeartrate(workout.getMaxHeartrate());
        jWorkout.setAvgHeartrate(workout.getAvgHeartrate());
        jWorkout.setStartWheel(workout.getStartWheel());
        jWorkout.setEndWheel(workout.getEndWheel());
        jWorkout.setMaxWheelRevolution(workout.getMaxWheelRevolution());//"maxWheelRpm"
        jWorkout.setLocSource(workout.getLocSource());
        jWorkout.setHeartSource(workout.getHeartSource());
        jWorkout.setCadenceSource(workout.getCadenceSource());
        jWorkout.setSegmentIndex(workout.getSegmentIndex() == null ? strEmpty : workout.getSegmentIndex());
        jWorkout.setSegmentKM(strEmpty);//workout.getSegmentKMSample(350) sst remove it, empty string instead, seems useless, todo sst
        jWorkout.setSegmentSport(workout.getSegmentSport() == null ? strEmpty : workout.getSegmentSport());
        jWorkout.setSegmentHr(workout.getSegmentHr() == null ? strEmpty : workout.getSegmentHr());
        jWorkout.setSegmentCa(workout.getSegmentCa() == null ? strEmpty : workout.getSegmentCa());
        jWorkout.setStep(workout.getStep());
        jWorkout.setCalorie(workout.getCalorie());
        jWorkout.setMaxSpeed(workout.getMaxSpeed());
        jWorkout.setEncodingPoints("");//woc server do not use this, set empty
        jWorkout.setMapId(0);//0 means original wgs84 data
        jWorkout.setMaxAltitude(workoutExtraInfo.getMaxAltitude());
        jWorkout.setAvgAltitude(workoutExtraInfo.getAvgAltitude());
        jWorkout.setMaxPower(workout.getMaxPower());
        jWorkout.setAvgPower(workout.getAvgPower());
        jWorkout.setAvgSpeed(workout.getAvgSpeed());
        jWorkout.setPowerSource(workout.getPowerSource());
        jWorkout.setPowerNP(workout.getPowerNP());
        jWorkout.setPowerIF(workout.getPowerIF());
        jWorkout.setPowerVI(workout.getPowerVI());
        jWorkout.setPowerTSS(workout.getPowerTSS());
        jWorkout.setPowerFTP(workout.getPowerFTP());
        jWorkout.setCategory(workout.getCategory());

        String mergeRecord = workout.getMergeRecord() == null ? strEmpty : workout.getMergeRecord();
        jWorkout.setMergeRecord(mergeRecord);

        return jWorkout;
    }




}
